<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['types']=array(
	'1'=>'普通订阅号',
	'2'=>'认证订阅号',
	'3'=>'普通服务号',
	'4'=>'认证服务号'
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'pluginname'=>'jy_kuaijiefee');
	if(!empty($_RQ['merchname'])){
		$params['merchname like']='%'.trim($_RQ['merchname']).'%';
		$return['params']['merchname']=$_RQ['merchname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['status']!=''){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['pcd']){
		$pcd=cfc('tools')->base64_decode($_RQ['pcd'],$_SESSION['base_key_str']);
		$pcd=json_decode($pcd,true);
		$return['params']['pcd']=$pcd;
	}
	if($pcd['province']){
		$params['pcd like']='%'.$pcd['province'].'%';
	}
	if($pcd['city']){
		$params['pcd like']='%'.$pcd['city'].'%';
	}
	if($pcd['district']){
		$params['pcd like']='%'.$pcd['district'].'%';
	}
	if($pcd['street']){
		$params['pcd like']='%'.$pcd['street'].'%';
	}
	$fields=array('id','setting','mid','star','groupid','isrecommand','salecate','cateid','mobile','realname','status','jointime','accounttime','logo','merchname','upass','uname','dd_shop_id');
    $orderby='star desc, id desc';
	$total='';
	$return['list']=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$_SESSION['page']=$pindex;
	foreach($return['list'] as &$v){
		$v['jointime']=date('Y/m/d H:i:s',$v['jointime']);
		$v['url']=custom_url('jy_merch/merch//id='.$v['id'],true);
		$v['appurl']='jy_merch/merch//id='.$v['id'];
		$v['member']=cfc('core')->member_show($v['mid']);
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid'],'uniacid'=>$_SESSION['uniacid']),'catename');
		$v['actionurl']='jy_merch/goods//merchid='.$v['id'];
		$v['addgoodsurl']='jy_merch/goods/edit/merchid='.$v['id'];
		$v['addgoodsurl']='jy_merch/goods/edit/merchid='.$v['id'];
		$v['onelogin']=custom_url('jy_merch/manage.login/onelogin/upass='.$v['upass'].'&uname='.$v['uname'],true);
		$v['setting']=$v['setting']?json_decode($v['setting'],true):array('ks_id'=>'');
		$v['ks_id']=$v['setting']['ks_id'];
	}
	$return['status']=array('0'=>array('id'=>0,'title'=>'待入驻'),'1'=>array('id'=>1,'title'=>'入驻中'),'2'=>array('id'=>2,'title'=>'暂停中'),'3'=>array('id'=>3,'title'=>'待缴押金'));
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'多商户管理'),
			array('op'=>'edit','title'=>'添加多商户'),
		),
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]:没有地址，经纬度，不在营业时间（休息）的商户，在某些情况下（外卖，附近商户等）可能不会显示出来！','list'=>array(
			array('title'=>'ID/MID','type'=>'img_string',
			'data'=>array(
				array('title'=>'ID：','name'=>'id'),
				array('title'=>'MID：','name'=>'mid')
				)
			),
			array('title'=>'商户信息_Merch','type'=>'img_string','img'=>'logo',
			'data'=>array(
				array('title'=>'名称：','name'=>'merchname'),
				array('title'=>'快手号：','name'=>'ks_id')
				)
			),
			array('title'=>'核销ID/时间','type'=>'img_string',
			'data'=>array(
				array('title'=>'ID:','name'=>'dd_shop_id'),
				array('title'=>'入驻：','name'=>'jointime')
				)
			),
			array('name'=>'setting.cname','title'=>'营业执照名称','type'=>'string'),	
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status2'),
			array('name'=>'isrecommand','title'=>'推荐？','type'=>'switch','set'=>'set'),
		),'action'=>array(
			//array('type'=>'href_blank','name'=>'onelogin','title'=>'一键登录'),
			//array('type'=>'modal','op'=>'look','title'=>'商户信息'),
			//array('type'=>'href','action'=>'/merchdata/','title'=>'商户数据'),
			//array('type'=>'modal','op'=>'setgroup','title'=>'设置商户等级'),
			//array('type'=>'href_item','action'=>'addgoodsurl','title'=>'添加商品_ADD Goods'),
			//array('type'=>'href_item','action'=>'actionurl','title'=>'商品管理_Goods'),
			array('type'=>'href','action'=>'/apply_add/','title'=>'提交结算'),
			//array('type'=>'post','op'=>'deldiyform','title'=>'清空表单'),
		),'batch'=>array(
			array('type'=>'modal','url'=>'jy_kuaijiefee/merch/apply_add/','title'=>'一键提交结算'),
		)),
		'search'=>array(
			array('name'=>'merchname','width'=>8,'title'=>'商户名称','type'=>'string'),
			array('name'=>'realname','width'=>8,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>8,'title'=>'电话','type'=>'string'),
			array('name'=>'status','width'=>8,'title'=>'状态','type'=>'select','options'=>'status'),
			array('type'=>'pcd2','width'=>'40','title'=>'区域','name'=>'pcd','help'=>''),
		)
	);
	$return['status2']=$this->merch_status;
	$return['group']=pdo_getall('jy_merch_group',array('uniacid'=>$_SESSION['uniacid']),array('id','groupname'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_merch_user',array('id'=>$id));
		$item['lat_lng']=json_decode($item['lat_lng']);
		$item['onlinetime']=json_decode($item['onlinetime'],true);
		$item['oldstatus']=$item['status'];
	}else{
		$item=array();
	}
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('province'=>'');
	$item['setting']=$item['setting']?json_decode($item['setting'],true):array('ks_id'=>'');
	$item['bankimg']=$item['setting']['bankimg'];
	$item['codeimg']=$item['setting']['codeimg'];
	$item['codeimg2']=$item['setting']['codeimg2'];
	$item['cardimg']=$item['setting']['cardimg'];
	$item['cardimg2']=$item['setting']['cardimg2'];
	if(!$item['pcd']['province']){
		$item['pcd']=array('province'=>'');
	}
	$choufee_set=$item['choufee_set']=$item['choufee_set']?json_decode($item['choufee_set'],true):array('commission_type'=>'0','shopcommission_type'=>'0');
	if(!is_array($choufee_set)){
		$choufee_set=array('commission_type'=>'0','shopcommission_type'=>'0');
	}
	//$item['datamids']=json_decode($item['datamids'],true);
	$choufee_set['rate']=$choufee_set['rate']?:0;	
	$item=array_merge($item,$choufee_set);
	$item['upass']='';
	if($item['onewechat']){
		$item['onewechat']=json_decode($item['onewechat'],true);
		if(!$item['onewechat']['token']){
			$item['onewechat']=array('isopen'=>0);
		}
	}else{
		$item['onewechat']=array('isopen'=>0);
	}
	$item['app']=$item['app']?json_decode($item['app'],true):array('isopen'=>0);
	$item['installbak']=$item['app']['installbak'];
	$item['appurl']=custom_url('jy_merch/getapp//merchid='.$item['id'],true);
	$item['url']=SITEROOT.'addons/jy_merch/wxapi.php?merchid='.$item['id'];
	$item['pluginset']=$item['pluginset']?json_decode($item['pluginset'],true):array('isopen'=>0);
	$item['plugins']=$item['pluginset']['plugins'];
	$item['games']=$item['pluginset']['games'];
	$item['onewechat']['token']=$item['onewechat']['token']?:random(30);
	$item['onewechat']['aeskey']=$item['onewechat']['aeskey']?:random(43);
	$item['cert_file']=$item['onewechat']['cert_file'];
	$item['key_file']=$item['onewechat']['key_file'];
	$item['viptime'] =$item['viptime']?date('Y/m/d H:i',$item['viptime']):'';
	$account_host=get_account_url();
	$account_tp=str_replace('http://','',$account_host).'custom/';
	$account_apitp=str_replace('http://','',$account_host).'app/';
	$account_url=str_replace('http://','',$account_host).'custom/payresult/wechat_notify.php';
    $return['item']=$item;
	$htmls=array( 
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'多商户设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'多商户管理'),
			array('op'=>'edit','title'=>'添加多商户'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'快手账号架设资料',
				'list'=>array(
					array('name'=>'merchname','must'=>true,'title'=>'线上门店名称','type'=>'string','help'=>'要上团购的线上门店名称'),
					array('name'=>'dd_shop_id','must'=>true,'title'=>'核销门店ID','type'=>'string'),
					array('name'=>'address','title'=>'门店实际地址','type'=>'string','help'=>'要上团购的门店实际文字地址'),	
					array('name'=>'setting.bankcard','title'=>'团购收款的银行卡卡号','type'=>'string','help'=>'用于团购收款的银行卡卡号;填写 法人名下银行卡卡号或 公司对公帐户'),
					array('name'=>'setting.bankname','title'=>'银行卡开户的总行和支行','type'=>'string','help'=>'银行卡开户的总行和支行;例如：中国建设银行 ，湖北省天长市龙东大道支行'),
					array('name'=>'setting.mobile','title'=>'银行卡开户时预留的手机号','type'=>'string','help'=>'银行卡开户时预留的手机号'),
					array('name'=>'bankimg','title'=>'法人银行卡照片','type'=>'image','help'=>'上传法人银行卡照片（或公司对公账户信息图或对公账户银行卡照片）个体工商户上传法人名下银行卡照片;公司 上传 对公账户信息图或对公账户银行卡照片'),
					array('name'=>'setting.cname','title'=>'营业执照名称','type'=>'string','help'=>'营业执照名称'),
					array('name'=>'codeimg','title'=>'营业执照','type'=>'image','help'=>'营业执照（四个边角露出，清晰可见）'),
					array('name'=>'cardimg','title'=>'身份证正面','type'=>'image','help'=>'（四个边角露出，清晰可见）'),
					array('name'=>'cardimg2','title'=>'身份证反面','type'=>'image','help'=>'（四个边角露出，清晰可见）'),
					array('name'=>'codeimg2','title'=>'卫生许可证或行业许可证','type'=>'image','help'=>'卫生许可证或行业许可证（四个边角露出，清晰可见）'),
					array('name'=>'setting.ks_id','title'=>'门店管理员快手号','type'=>'string','help'=>'门店管理员快手号'),
					array('name'=>'mobile','title'=>'门店管理员手机号','type'=>'string','help'=>'门店管理员手机号'),
					array('name'=>'setting.heks_id','title'=>'门店核销快手号','type'=>'string','help'=>'门店核销快手号'),
					array('name'=>'setting.hemobile','title'=>'门店核销手机号','type'=>'string','help'=>'门店核销手机号'),
					array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
				)
			),
			array(
					'title'=>'店长信息/二维码',
					'list'=>array(
						array('name'=>'uname','must'=>true,'title'=>'账户名','type'=>'string'),
						array('name'=>'upass','title'=>'账户密码','type'=>'string'),
						array('name'=>'mid','title'=>'选择管理员','type'=>'choose','action'=>'core/member.get_member/'),	
						array('name'=>'payopenid','title'=>'选择收款人','type'=>'choose_title','action'=>'core/member.get_member/'),
						array('type'=>'image','title'=>'群聊二维码','name'=>'qunewm'),
					)
				),
				array(
					'title'=>'抽成设置',
					'list'=>array(
						//array('name'=>'payrate','title'=>'抽成利率（%）','type'=>'string'),
						array('type'=>'unitstring','name'=>'rate','unit'=>'%','title'=>'抽成比例','help'=>'按百分比算：例如5，表示收起5%'),
					)
			),
		)
	);
	$citypeisong=plugin('jy_weishop')->plugin_setting('citypeisong');
	$return['fuwu_types']=$this->fuwu_types;
	$return['yuyue_types']=$this->yuyue_types;
	$return['sendtypes']=array(
		'1'=>'同城配送',
		'2'=>'到店自取',
		'4'=>'快递配送',
	);
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	$return['cate2']=array();
	foreach($return['cate'] as $cv){
		$return['cate2'][$cv['id']]=$cv['catename'];
	}
	$return['group']=pdo_getall('jy_merch_group',array('uniacid'=>$_SESSION['uniacid']),array('id','groupname'),'id');
	$return['status']=$this->merch_status;
	$return['status2']=array('1'=>'是','0'=>'否');
	$return['commission_types']=$this->commission_types;
	$return['merch_type']=$this->merch_type;
	unset($return['commission_types'][3]);
	$return['dish_feetypes']=$this->dish_feetypes;
	$return['shop_feetypes']=$this->shop_feetypes;
	$return['no_feetypes']=$this->no_feetypes;
	$return['plugins']=$this->model('model')->get_plugins();
	$return['games']=$this->model('model')->get_games();
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['merchname']){
		exi('门店名称必填','error');
	}
	if(!$post['dd_shop_id']){
		exi('门店核销ID必填','error');
	}
	if($post['oldstatus']==1 && $post['status']!=1 && $post['id']){
		pdo_update('jy_weishop_goods',array('nochecked'=>1),array('merchid'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	}
    $oldmerch=pdo_get('jy_merch_user',array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	$infomid=pdo_getcolumn('jy_merch_user',array('mid'=>$post['mid'],'uniacid'=>$_SESSION['uniacid']),'mid');
	$uname=pdo_get('jy_merch_user',array('uname'=>$post['uname'],'uniacid'=>$_SESSION['uniacid']));
	$post['choufee_set']=array(
		'cong_choufee'=>$post['cong_choufee'],
		'commission_type'=>0,
		'dish_feetype'=>$post['dish_feetype'],
		'no_feetype'=>$post['no_feetype'],
		'rate'=>$post['rate'],
		'rateyuan'=>$post['rateyuan'],
		'ratejieti'=>$post['ratejieti'],
		'shopcommission_type'=>0,
		'shop_feetype'=>$post['shop_feetype'],
		'shopno_feetype'=>$post['shopno_feetype'],
		'shoprate'=>$post['shoprate'],
		'shoprateyuan'=>$post['shoprateyuan'],
		'shopratejieti'=>$post['shopratejieti'],
		'koucredit_rate'=>$post['choufee_set']['koucredit_rate'],
	);
	$post['app']['installbak']=$post['installbak'];
	$post['onewechat']['cert_file']=$post['cert_file'];
	$post['onewechat']['key_file']=$post['key_file'];
	$post['pluginset']['plugins']=$post['plugins'];
	$post['pluginset']['games']=$post['games'];
	$post['setting']['bankimg']=$post['bankimg'];
	$post['setting']['codeimg']=$post['codeimg'];
	$post['setting']['codeimg2']=$post['codeimg2'];
	$post['setting']['cardimg']=$post['cardimg'];
	$post['setting']['cardimg2']=$post['cardimg2'];
	$data =array(
		'type'=>intval($post['type']),
		'uname'=>$post['uname'],
		'dd_shop_id'=>$post['dd_shop_id'],
		'upass'=>base64_encode($post['upass']),
		'mobile'=>$post['mobile'],
		'realname'=>$post['realname'],
		'merchname'=>$post['merchname'],
		'wechat'=>$post['wechat'],
		'offline'=>intval($post['offline']),
		'onlinetime'=>ijson_encode($post['onlinetime']),
		'logo'=>$post['logo'],
		'topimg'=>$post['topimg'],
		'desc'=>$post['desc'],
		'remark'=>$post['remark'],
		'salecate'=>$post['salecate'],
		'status'=>$post['status'],
		'address'=>$post['address'],
		'lat_lng'=>ijson_encode($post['lat_lng']),
		'mid'=>$post['mid'],
		'cateid'=>intval($post['cateid']),
		'cateid2'=>trim($post['cateid2']),
		'star'=>intval($post['star']),
		'sudu'=>intval($post['sudu']),
		'isrecommand'=>$post['isrecommand'],
		'tel'=>$post['tel'],
		'out_pay'=>$post['out_pay'],
		'out_price'=>$post['out_price'],
		'man_fee'=>$post['man_fee'],
		'salenum'=>$post['salenum'],
		'groupid'=>$post['groupid'],
		'payrate'=>0,
		'payopenid'=>$post['payopenid'],
		'isbrand'=>$post['isbrand'],
		'content'=>trim($post['content']),
		'mypeisong'=>$post['mypeisong'],
		'ismake'=>intval($post['ismake']),
		'isjiedan'=>intval($post['isjiedan']),
		'out_juli'=>$post['out_juli'],
		'out_upfee'=>$post['out_upfee'],
		'choufee_set'=>ijson_encode($post['choufee_set']),
		'codeimg'=>ijson_encode($post['codeimg']),
		'pcd'=>ijson_encode($post['pcd']),
		'sendtype'=>intval($post['sendtype']),
		'opensendtype'=>trim($post['opensendtype']),
		'fuwu_type'=>trim($post['fuwu_type']),
		'yuyue_type'=>trim($post['yuyue_type']),
		'onewechat'=>ijson_encode($post['onewechat']),
		'app'=>ijson_encode($post['app']),
		'pluginset'=>ijson_encode($post['pluginset']),
		'setting'=>ijson_encode($post['setting']),
		'viptime'=>strtotime($post['viptime']),
		'is_moregoods'=>intval($post['is_moregoods']),
		'qunewm'=>trim($post['qunewm']),
	);
	$isadd=pdo_get('jy_merch_user',array('dd_shop_id'=>$data['dd_shop_id'],'uniacid'=>$_SESSION['uniacid']),array('id'));
	if($isadd['id'] && $isadd['id']!=$post['id']){
		exi('该核销门店ID注册过！','error');
	}
	if($post['id']){
		$_SESSION['isopenid'.$post['id']]=0;
		if(!$post['upass']){
			unset($data['upass']);
		}
		if($infomid && $infomid!=$post['mid']){
			//exi('一个管理员只能绑定一个账号','error');
		}
		if($uname && $uname['id']!=$post['id']){
			exi('登陆账户名不可以重复','error');	
		}
        if($oldmerch['groupid']!=$data['groupid'] && $data['mid']){
            $this->model('model')->upmember($data['groupid'],$data['mid']);
        }
		pdo_update('jy_merch_user',$data,array('id'=>$post['id']));
		exi('保存成功','','//list/page='.$_SESSION['page']);
	}else{
		if($uname){
			exi('登陆账户名不可以重复','error');	
		}
		if($infomid){
			//exi('一个管理员只能绑定一个账号','error');
		}
		$data['uniacid']=$_SESSION['uniacid'];
		$data['pluginname']='jy_kuaijiefee';
		$data['jointime']=time();
		pdo_insert('jy_merch_user',$data);
		exi('添加成功','','list');
	}	
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_merch_user',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_merch_user',array('id'=>$id));	
			}
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='star'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['star'])){
		$update['star']=$post['star'];
	}
	if($update){
		pdo_update('jy_merch_user',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_merch_user',array('id'=>$id));
		$item['lat_lng']=json_decode($item['lat_lng']);
		$item['onlinetime']=json_decode($item['onlinetime'],true);
	}else{
		$item=array();
	}
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['upass']='';
	$item['diyformdata']=$item['diyformdata']?json_decode($item['diyformdata'],true):array();
	$formtypes=get_form_types();	
	foreach($item['diyformdata'] as &$v){
		if($v['type']==5 && $v['data']){
			$v['data'] = explode(";", $v['data']);
			foreach($v['data'] as $k=>&$i){
				if(empty($v['data'][$k])){
					unset($v['data'][$k]);
				}
			}
		}
		//$v['type']=$formtypes[$v['type']];
	}
    $return['item']=$item;
	$htmls=array( 
		'type'=>'look',
		'desc'=>'商户详情',
		'look'=>array(
			array('name'=>'merchname','title'=>'商户名称','type'=>'string'),
			array('name'=>'logo','title'=>'商户logo','type'=>'image'),
			array('type'=>'image','title'=>'店招','name'=>'topimg'),
			array('name'=>'isbrand','title'=>'属于品牌？','type'=>'switch'),
			array('name'=>'salecate','title'=>'主营项目','type'=>'string'),	
			array('name'=>'cateid','title'=>'商户分类','type'=>'select','options'=>'cate','option_title'=>'catename'),
			array('name'=>'realname','title'=>'联系人','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'desc','title'=>'商户简介','type'=>'text'),
			array('type'=>'text','title'=>'商户公告','name'=>'remark'),
			array('name'=>'address','title'=>'商户地址','type'=>'string'),	
			array('name'=>'tel','title'=>'商户电话','type'=>'string'),
			array('name'=>'groupid','title'=>'商户组','type'=>'select','options'=>'group','option_title'=>'groupname'),	
			array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
			array('name'=>'content','title'=>'商户详情','type'=>'richtext'),
			array(
						'title'=>'其他信息',
						'type'=>'array',
						'name'=>'diyformdata',
						'list'=>array(
							array('type'=>'string','name'=>'title','title'=>'表单标题'),	
							array('type'=>'labelarray','name'=>'data','title'=>'表单内容'),	
						),
			)
		)
	);
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	$return['group']=pdo_getall('jy_merch_group',array('uniacid'=>$_SESSION['uniacid']),array('id','groupname'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先操作商户！','error');
	}
	$post=get_postdata();
	if(isset($post['isrecommand'])){
		pdo_update('jy_merch_user',array('isrecommand'=>intval($post['isrecommand'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='setstatus0'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择商户','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			pdo_update('jy_merch_user',array('status'=>0),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	
	exi('待入驻成功！');
}
if($_RQ['op']=='setstatus1'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择商户','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			pdo_update('jy_merch_user',array('status'=>1),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	
	exi('入驻成功！');
}
if($_RQ['op']=='setstatus2'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择商户','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			pdo_update('jy_merch_user',array('status'=>2),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	
	exi('暂停成功！');
}
if($_RQ['op']=='setstatus3'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择商户','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			pdo_update('jy_merch_user',array('status'=>3),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	
	exi('待缴押金成功！');
}
if($_RQ['op']=='deldiyform'){
	$id=trim($_RQ['id']);
	if(!$id){
		exi('请先选择商户','error');
	}
	pdo_update('jy_merch_user',array('diyformdata'=>''),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
if($_RQ['op']=='apply_add'){
	$setting=plugin('jy_merch')->plugin_setting('setting');
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if($setting['tixian_timetype']==1 && (!$postdata['year'] || !$postdata['month'])){
			exi('请选择年份，月份！','error');
		}
		$year=intval(date('Y',time()));
		$month=intval(date('m',time()));
		if($year==$postdata['year'] && $postdata['month']>=$month){
			exi('不能选择本月及以后月份！','error');
		}
		if($setting['tixian_timetype']==1 && $setting['tixian_timeday'] && $year==$postdata['year'] && $postdata['month']==$month-1){
			$nowyuetime=mktime(0,0,0,date('m'),1,date('Y'));
			if($nowyuetime+24*3600*($setting['tixian_timeday']-1)>time()){
				exi('次月第'.$setting['tixian_timeday'].'天开始结算！','error');
			}
		}
		if($year==$postdata['year'] && $postdata['month']>=$month){
			exi('不能选择本月及以后月份！','error');
		}
		$this->model('tixian')->addall($postdata['year'],$postdata['month']);
		exi('操作成功！','','/tixian/');
	}
	
	$year=intval(date('Y',time()));
	$return['year']=array('0'=>array('id'=>$year-9,'title'=>$year-9),'1'=>array('id'=>$year-8,'title'=>$year-8),'2'=>array('id'=>$year-7,'title'=>$year-7),'3'=>array('id'=>$year-6,'title'=>$year-6),'4'=>array('id'=>$year-5,'title'=>$year-5),'5'=>array('id'=>$year-4,'title'=>$year-4),'6'=>array('id'=>$year-3,'title'=>$year-3),'7'=>array('id'=>$year-2,'title'=>$year-2),'8'=>array('id'=>$year-1,'title'=>$year-1),'9'=>array('id'=>$year,'title'=>$year));
	$return['month']=array('0'=>array('id'=>1,'title'=>1),'1'=>array('id'=>2,'title'=>2),'2'=>array('id'=>3,'title'=>3),'3'=>array('id'=>4,'title'=>4),'4'=>array('id'=>5,'title'=>5),'5'=>array('id'=>6,'title'=>6),'6'=>array('id'=>7,'title'=>7),'7'=>array('id'=>8,'title'=>8),'8'=>array('id'=>9,'title'=>9),'9'=>array('id'=>10,'title'=>10),'10'=>array('id'=>11,'title'=>11),'11'=>array('id'=>12,'title'=>12));
	if($setting['tixian_timetype']==1){
		$tixian_timeday=$setting['tixian_timeday']?:1;
		$tixian_timetips='按月结算，请选择要结算的月份，次月第'.$tixian_timeday.'天可结算！';
	}else{
		$tixian_timetips='订单完成就后，随时可结算！';
	}
	$item['tixian_timetype']=$setting['tixian_timetype'];
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'edit'=>array(
			array('title'=>'[温馨提示]：每次最大提现1000个订单；如订单过多，需要分批结算；','type'=>'tip'),
			array('title'=>$tixian_timetips,'type'=>'title'),
			array('name'=>'year','title'=>'选择年份','type'=>'select','options'=>'year','show'=>array('tixian_timetype'=>1)),
			array('name'=>'month','title'=>'选择月份','type'=>'select','options'=>'month','show'=>array('tixian_timetype'=>1)),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
?>